home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_course.zip / BIGDYNL.C < prev    next >
Text File  |  1989-12-30  |  1KB  |  36 lines

  1. main()
  2. {
  3. struct animal {
  4.    char name[25];
  5.    char breed[25];
  6.    int age;
  7. } *pet[12], *point;   /* this defines 13 pointers, no variables */
  8. int index;
  9.  
  10.             /* first, fill the dynamic structures with nonsense */
  11.    for (index = 0;index < 12;index++) {
  12.       pet[index] = (struct animal *)malloc(sizeof(struct animal));
  13.       strcpy(pet[index]->name,"General");
  14.       strcpy(pet[index]->breed,"Mixed Breed");
  15.       pet[index]->age = 4;
  16.    }
  17.  
  18.    pet[4]->age = 12;        /* these lines are simply to        */
  19.    pet[5]->age = 15;        /*      put some nonsense data into */
  20.    pet[6]->age = 10;        /*            a few of the fields.  */
  21.  
  22.        /* now print out the data described above */
  23.  
  24.    for (index = 0;index <12;index++) {
  25.       point = pet[index];
  26.       printf("%s is a %s, and is %d years old.\n", point->name,
  27.               point->breed, point->age);
  28.    }
  29.  
  30.        /* good programming practice dictates that we free up the */
  31.        /* dynamically allocated space before we quit.            */
  32.  
  33.    for (index = 0;index < 12;index++)
  34.       free(pet[index]);
  35. }
  36.